package animator.phantom.gui;

/*
    Copyright Janne Liljeblad 2006,2007,2008

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import animator.phantom.controller.PreviewController;
import animator.phantom.controller.EditorPersistance;
import java.awt.*;

public class AnimatorFrameLayout implements LayoutManager
{
	//--- Components that are layed out.
	private Component tabsEditArea;
	private Component flowEditor;
	private Component timeEditor;
	
	private static Dimension containerSize;

	//--- 
	public static int MID_Y = EditorPersistance.getIntPref( EditorPersistance.LAYOUT_MID );
	private static int SMALL_WINDOW_WIDTH = ContentPaneLayout.LEFT_WIDTH;

	//--- Layout params for flowEditor.
	private static int FLOW_X = 0;
	private static int FLOW_Y = 0;
	public static int FLOW_H = MID_Y + 4;

	//--- Layout params for timeEditor
	private static int TIME_X = 0;
	private static int TIME_Y = MID_Y;

	public AnimatorFrameLayout( 	Component flowEditor,
					Component timeEditor )
	{
		this.flowEditor = flowEditor;
		this.timeEditor = timeEditor;
	}

	//--- Layout is performed here
    	public void layoutContainer(Container cont) 
	{
		synchronized (cont.getTreeLock()) 
		{
			containerSize = cont.getSize();

			int comps = cont.getComponentCount();
			for (int i = 0 ; i < comps ; i++) 
			{
				Component c = cont.getComponent(i);
				if( c == flowEditor ) layoutFlow(c);
				if( c == timeEditor ) layoutTime(c);
			}
		}
    	}
	//--- Set bounds for flow.
	private void layoutFlow( Component flow )
	{
		int FLOW_W = containerSize.width;
		flow.setBounds( FLOW_X, FLOW_Y, FLOW_W, FLOW_H );
	}

	//--- Set bounds for time.
	private void layoutTime( Component time )
	{
		int TIME_W = containerSize.width;
		int TIME_H = containerSize.height - TIME_Y;
		time.setBounds( TIME_X, TIME_Y, TIME_W, TIME_H );
	}

	//--------------------------------------------------- LAYOUT MANAGER METHODS
	//--- noop
	public void addLayoutComponent(String name, Component comp) {}
	//--- noop
	public void removeLayoutComponent(Component comp) {}
	//--- Preferred size of layout is preferred size of Container that is being layed out.
	public Dimension preferredLayoutSize(Container target) 
	{ 
		return new Dimension( Toolkit.getDefaultToolkit().getScreenSize().width - SMALL_WINDOW_WIDTH - 10,
					Toolkit.getDefaultToolkit().getScreenSize().height - 2 );
	}
	//--- Minimum size of layout is minimum size of Container that is being layed out.
	public Dimension minimumLayoutSize(Container target) { return new Dimension( 500, 500 ); }

}//end class
